/*
This is exactly why C++ was invented - to group functions together into
classes. Look at following (incorrect) code:

int f(int i)
{
int j = i + 1;
int a() // local function is invalid!
{
return j * i;
};

return a() + i;
}

it won't work, but you can use class instead:

class f {
const int& i; // variables shared between all ...
int j; // ... functions grouped into class
int ret; // return value
int a() // "internal" function
{
return j * i;
}
public:
f(const int& arg_i) : i(arg_i), j(i + 1)
{
ret = a() + i;
}

operator int() {return ret;}
// bonus: alternate return type from function object
operator std::string() {return "hi!";}
};

You may call your function object simply creating it:
int r = f(3);

you may also retrieve its "alternate" return value:
std::string q = f(4);

regards


B.
*/

#include <iostream>

using namespace std;
class f {
	const int& i; // variables shared between all ...
	int j; // ... functions grouped into class
	int ret; // return value
	int a() // "internal" function
		{
		return j * i;
		}
public:
		f(const int& arg_i) : i(arg_i), j(i + 1)
		{
			ret = a() + i;
		}

		// operator int() {return ret;}
		 operator float() {return ret;}
		// bonus: alternate return type from function object
		operator std::string() {return "hi!";}
};

int main(){
	int i=f(3);
	cout << i << endl;
	string s=f(5);
	float f1=f(5);
	char* b=f(5);
	cout << s << endl;
	cout << f1 << endl;
}
